//
//  BottomActionView.m
//  CMVRFForIOS
//
//  Created by zhangnorman on 15/4/7.
//  Copyright (c) 2015年 hvacapp. All rights reserved.
//

#import "BottomActionView.h"

@interface BottomActionView()



@property (nonatomic,strong) UIButton *leftBtn;
@property (nonatomic,strong) UIImageView *centerView;
@property (nonatomic,strong) UILabel *centerLabel;
@property (nonatomic,strong) UIButton *rightBtn;

@property (nonatomic, copy) void(^leftBtnOnClick)(id);
@property (nonatomic, copy) void(^rightBtnOnClick)(id);

@end

@implementation BottomActionView


- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        [self setupVies];
    }
    return self;
}

- (void)setupVies {
    UIImage *image = [UIImage imageNamed:@"bottom_action_center"];

    
    //中间的背景图
    self.centerView = [[UIImageView alloc]initWithImage:image];
    self.centerView.height = self.height;
    self.centerView.width = self.height;
    self.centerView.centerX = self.width/2;
    self.centerView.y = 0;
    [self addSubview:self.centerView];
    
    //中间显示文字的label
    self.centerLabel = [UILabel labelSingleLineFontSize:12 content:@"1/8"];
    self.centerLabel.textColor = CM_TABLE_TITLE_COLOR;
    self.centerLabel.width += 6;
    self.centerLabel.centerX = kScreen_Width/2;
    self.centerLabel.centerY = self.height/2;
    
    [self addSubview:self.centerLabel];
    
    //左边的按钮
    self.leftBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, (self.width - self.centerView.width)/2, self.height)];
    self.leftBtn.backgroundColor = CM_DARKGREEN_COLOR;
    self.leftBtn.titleLabel.textColor = [UIColor whiteColor];
    self.leftBtn.titleLabel.font = [UIFont systemFontOfSize:kNavTitleFontSize];
    [self.leftBtn addTarget:self action:@selector(onLeftBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.leftBtn];
    
    //右边的按钮
    self.rightBtn = [[UIButton alloc]initWithFrame:CGRectMake((self.width + self.centerView.width)/2, 0, (self.width - self.centerView.width)/2, self.height)];
    self.rightBtn.backgroundColor = CM_ORANGE_COLOR;
    self.rightBtn.titleLabel.textColor = [UIColor whiteColor];
    self.rightBtn.titleLabel.font = [UIFont systemFontOfSize:kNavTitleFontSize];
    [self.rightBtn addTarget:self action:@selector(onRightBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.rightBtn];
}

- (void)addLeftBtnBlock:(void (^)(id))leftAction {
    self.leftBtnOnClick = leftAction;
    
}

- (void)addRightBtnBlock:(void (^)(id))righAction {
    self.rightBtnOnClick = righAction;
}

- (void)setLeftBtnTitle:(NSString*)leftStr andRightBtnTitle:(NSString*)rightStr andCenterTitle:(NSString*)centerStr{
    [self.leftBtn setTitle:leftStr forState:UIControlStateNormal];
    [self.rightBtn setTitle:rightStr forState:UIControlStateNormal];
    self.centerLabel.text = centerStr;
}

- (void)updateCenterTitle:(NSString*)centerStr{
    self.centerLabel.text = centerStr;
}



- (void)onLeftBtnClick {
    if (self.leftBtnOnClick) {
        self.leftBtnOnClick(self.leftBtn);
    }
}

- (void)onRightBtnClick {
    if (self.rightBtnOnClick) {
        self.rightBtnOnClick(self.rightBtn);
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
